<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('analyses', function (Blueprint $table) {
            $table->id();
            $table->nullableMorphs('dev');
            $table->string('type')->nullable(true)->comment('类别');
            $table->string('result')->nullable(true)->comment('分析结果');
            $table->string('user_name')->nullable(true)->comment('用户名称');
            $table->unsignedBigInteger('user_id')->nullable(true)->comment('用户id');
            $table->timestamp('begin_at')->nullable(true)->comment('起始时间');
            $table->timestamp('end_at')->nullable(true)->comment('结束时间');
            $table->string('remarks')->nullable(true)->comment('备注');
            $table->unsignedBigInteger('correction_id')->comment('电芯id');
            $table->timestamps();
        });
        Schema::create('corrections', function (Blueprint $table) {
            $table->id();
            $table->nullableMorphs('dev');
            $table->string('type')->nullable(true)->comment('类别');
            $table->json('deviation')->nullable(true)->comment('误差信息(json)');
            $table->json('deviation_rank')->nullable(true)->comment('误差排行(json)');
            $table->json('advice')->nullable(true)->comment('校正建议(json)');
            $table->json('error_curve')->nullable(true)->comment('误差曲线');
            $table->string('remarks')->nullable(true)->comment('备注');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('analyses');
        Schema::dropIfExists('corrections');
    }
};
